﻿
@{
    ViewBag.MainMenu = "Campaign";
    ViewBag.LeftMenu = "Donation";

    ViewBag.Title = "在线捐款";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<script language="javascript">

    var _mode = "create";//modify

    var _donation;

    $(document).ready(function ()
    {
        setOnlyMember();

        loadData();
    });

    function loadData()
    {
        var id = getQueryString("id");
        if (id == undefined || id == "")
        {
            return;
        }

        _mode = "modify";
        $("#btnRemove").show();

        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: "/Api/Campaign/GetDonationBundle?id=" + id,
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR)
            {
                layer.close(loadLayerIndex);
                if (data.Success)
                {
                    var campaign = data.Data.Campaign;
                    _donation = data.Data.Donation;

                    setCampaign(campaign);
                    //$("#txtPoint").val(_donation.Point);
                    //$("#selectMode").find("option[value='" + _donation.Mode + "']").attr("selected", true);
                    //$("#txtDrawCount").val(_donation.DrawCount);
                } else
                {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function save()
    {
        //if (_campaignBaseInfoValidator.form() == false || _validator.form() == false)
        if (_campaignBaseInfoValidator.form() == false )
        {
            return;
        }

        var campaign = getCampaign();

        if (_donation == undefined || _donation == null)
        {
            _donation = new Object();
        }

        //_donation.Point = $("#txtPoint").val();
        //_donation.Mode = $("#selectMode").val();
        //_donation.DrawCount = $("#txtDrawCount").val();

        var bundle = new Object();
        bundle.Campaign = campaign;
        bundle.Donation = _donation;

        var url = "/Api/Campaign/CreateDonation";

        if (_mode == "modify")
        {
            campaign.Id = $("#txtId").val();
            url = "/Api/Campaign/UpdateDonation";
        }

        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: url,
            type: "POST",
            dataType: "json",
            data: JSON.stringify(bundle),
            success: function (data, status, jqXHR)
            {
                if (data.Success)
                {
                    window.location.href = "/Campaign/Donation_Preparatory";

                } else
                {
                    layer.close(loadLayerIndex);
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function cancel()
    {
        window.location.href = "/Campaign/Donation_Preparatory";
    }

    function removeData()
    {
        var id = $("#txtId").val();
        if (id == undefined || id == "")
        {
            return;
        }

        var msg = "是否确认删除该活动？"

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function ()
        {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: "/Api/Campaign/RemoveDonation?id=" + id,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR)
                {
                    if (data.Success)
                    {
                        window.location.href = "/Campaign/Donation_Preparatory";
                    } else
                    {
                        layer.close(loadLayerIndex);
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest)
                {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });
    }


</script>


<div style=" margin-top:25px; margin-left:10px;" class="font_black_24">
    发起活动
</div>

<div class="divDotLine" style="margin-top:15px;"></div>

<div style="margin-top:25px;">
    @Helpers.CampaignBaseEdit()
</div>


<div style="margin-top:25px;">
    <div style="float:right;">
        <input name="btnRemove" type="button" class="btn_red" id="btnRemove" value="删 除" style="display:none" onclick="removeData()" />
    </div>
    <div style="float:left">
        <input name="btnSave" type="button" class="btn_blue" id="btnSave" value="保 存" onclick="save()" />
        <input name="btnCancel" type="button" class="btn_blue" id="btnCancel" value="取 消" onclick="cancel()" />
    </div>
    <div style="clear:both"></div>
</div>
@Helpers.FileUpload()






